package cn.com.huzo.service.master.impl;

import cn.com.huzo.model.entities.master.MaterialPictureEntity;
import cn.com.huzo.repository.master.MaterialPictureRepository;
import cn.com.huzo.service.master.MaterialPictureManager;
import huzofw.common.util.file.DeleteDirectoryAndFile;
import huzofw.service.impl.GenericManagerImpl;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 材料图片管理服务对象类实现。
 *
 * @author 吴旭
 */
@Service("MaterialPictureManager")
public class MaterialPictureManagerImpl extends GenericManagerImpl<MaterialPictureEntity, String>
        implements MaterialPictureManager {
    
    @Resource(name = "MaterialPictureRepository")
    private MaterialPictureRepository _dao_picture;

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Transactional
    @Override
    public List<MaterialPictureEntity> fetchAll(Long materialKey) throws Exception {
        return _dao_picture.fetchAll(materialKey);
    }

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Transactional
    @Override
    public String insert(MaterialPictureEntity instance) throws Exception {
        return _dao_picture.insert(instance);
    }

    /**
     * {@inheritDoc}
     *
     * @throws java.lang.Exception
     */
    @Transactional
    @Override
    public Integer delete(MaterialPictureEntity instance) throws Exception {
        DeleteDirectoryAndFile.deleteFile(instance.getImageFileDir() + "/" + instance.getImageFileName());
        return _dao_picture.delete(instance.getLinesId());
    }
}
